//
//  RMMMineWalletTableViewCell.m
//  Romomo
//
//  Created by puman on 2016/12/28.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMMineWalletTableViewCell.h"

@implementation RMMMineWalletTableViewCell
{
    UIButton *_cardBut;
    UIButton *_youHuiBut;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(15, kRow, kScreenWideth - 30, kHalf * 2)];
        view.layer.masksToBounds = YES;
        view.layer.cornerRadius = 5;
        view.layer.borderWidth = 1;
        view.layer.borderColor = RGBA(239, 239, 239, 1).CGColor;
        view.backgroundColor = kWhiteColor;
        [self.contentView addSubview:view];
        
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 45 * i, view.width, 45)];
                subView.backgroundColor = RGBA(245, 246, 247, 1);
                [view addSubview:subView];
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 100, subView.height)];
                label.text = @"我的钱包";
                label.textColor = COLORFROMCODE(0x2C2C2C, 1);
                label.font = kFont(14);
                [subView addSubview:label];
                
                UILabel *tiShiLabel = [[UILabel alloc] initWithFrame:CGRectMake(label.right, 0, view.width - label.right - 28, subView.height)];
                tiShiLabel.textColor = COLORFROMCODE(0x9B9B9B, 1);
                tiShiLabel.font = kFont(13);
                tiShiLabel.text = @"退款记录、管理支付方式";
                tiShiLabel.textAlignment = NSTextAlignmentRight;
                [subView addSubview:tiShiLabel];
                
                UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(tiShiLabel.right, 14.5, 16, 16)];
                imageV.image = [UIImage imageNamed:@"more-2@3x"];
                [subView addSubview:imageV];
            } else {
                CGFloat w = (view.width - 1) / 2.0;
                NSArray *imageArr = @[@"会员看支付@3x",@"优惠券@3x"];
                NSArray *titleArr = @[@"会员卡 ¥0.00",@"优惠券 0张"];
                for (int i = 0; i < 2; i++) {
                    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
                    button.frame = CGRectMake((w + 1) * i, 45, w, 55);
                    [button setImage:[UIImage imageNamed:imageArr[i]] forState:(UIControlStateNormal)];
                    [button setTitle:titleArr[i] forState:(UIControlStateNormal)];
                    button.userInteractionEnabled = NO;
                    [view addSubview:button];
                    button.titleLabel.font = kFont(14);
                    [button setTitleColor:COLORFROMCODE(0x000000, 1) forState:(UIControlStateNormal)];
                    [self changedLabelColorAndFontWithLabel:button.titleLabel ByString:titleArr[i] color:COLORFROMCODE(0x9B9B9B, 1)];
                    if (i == 0) {
                        _cardBut = button;
                        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(button.right, button.top + 5, 1, 45)];
                        lineView.backgroundColor = RGBA(245, 246, 247, 1);
                        [view addSubview:lineView];
                    } else {
                        _youHuiBut = button;
                    }
                }
            }
        }
    }
    return self;
}
- (void)changedLabelColorAndFontWithLabel:(UILabel *)label ByString:(NSString *)string color:(UIColor *)color{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
    [attributedString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(3, string.length - 3)];
    [attributedString addAttribute:NSFontAttributeName value:kFont(13) range:NSMakeRange(3, string.length - 3)];
    [label setAttributedText:attributedString];


}
- (void)setBalance:(NSString *)balance{
    [_cardBut setTitle:[NSString stringWithFormat:@"会员卡 ¥%@",balance] forState:(UIControlStateNormal)];
    [self changedLabelColorAndFontWithLabel:_cardBut.titleLabel ByString:[_cardBut titleForState:(UIControlStateNormal)] color:COLORFROMCODE(0x9B9B9B, 1)];
}
- (void)setCardCount:(NSString *)cardCount{
    [_youHuiBut setTitle:[NSString stringWithFormat:@"优惠券 %@张",cardCount] forState:(UIControlStateNormal)];
    [self changedLabelColorAndFontWithLabel:_youHuiBut.titleLabel ByString:[_youHuiBut titleForState:(UIControlStateNormal)] color:COLORFROMCODE(0x9B9B9B, 1)];

}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
